import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Demo_902 {
    public static void main(String[] args) throws InterruptedException{
        //创建一个线程，容量为3
        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        //向线程池中添加任务
        for (int i=0;i<10;i++){
            int takeId = i+1;
            //通过submit方法想线程池添加任务
            threadPool.submit(()->{
                System.out.println("执行任务: "+takeId+","+Thread.currentThread().getName());
            });

            if (takeId%2==0){
                //休眠
                TimeUnit.SECONDS.sleep(1);
            }
        }
    }
}
